﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SimpleUnitity
{
    public static class TypeLoader
    {

        public static Type Get(string assemblyType)
        {
            assemblyType = assemblyType.Trim();
            Type type = null;
            if (assemblyType.IndexOf(",") == -1)
            {
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    type = assembly.GetType(assemblyType);
                    if (type != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                string typeName = assemblyType.Split(',')[0].Trim();
                string assemblyName = assemblyType.Split(',')[1].Trim();
                type = AppDomain.CurrentDomain.Load(assemblyName).GetType(typeName);
            }
            if (type != null)
            {
                return type;
            }
            else
            {
                throw new TypeLoadException(string.Format("Can not found type: {0}", assemblyType));
            }
        }

    }
}
